package com.fbli.service.Impl;

import com.fbli.mapper.KnowledgeMapper;
import com.fbli.pojo.Knowledge;
import com.fbli.pojo.Products;
import com.fbli.service.KnowledgeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
@Service
public class KnowledgeServiceImpl implements KnowledgeService {
    @Autowired
    private KnowledgeMapper knowledgeMapper;
    @Override
    public PageInfo<Knowledge> selectPage(Knowledge knowledge, int pageNum, int pageSize) {
        //分页开始
        PageHelper.startPage(pageNum, pageSize);
        List<Knowledge> knowledges = knowledgeMapper.selectCondition(knowledge);
        //返回分页后的结果
        PageInfo<Knowledge> knowledgesPageInfo = new PageInfo<>(knowledges);
        return knowledgesPageInfo;
    }

    @Override
    public void deleteById(long[] ids) {
        for (long id:ids){
            knowledgeMapper.deleteByPrimaryKey((int) id);
        }

    }

    @Override
    public Knowledge selectById(int id) {
        return knowledgeMapper.selectByPrimaryKey(id);
    }

    @Override
    public void update(Knowledge knowledge) {
        Timestamp time = new Timestamp(new Date().getTime());
        knowledge.setReleaseTime(time);
        knowledgeMapper.updateByPrimaryKey(knowledge);
    }

    @Override
    public void insert(Knowledge knowledge) {
        Timestamp time = new Timestamp(new Date().getTime());
        knowledge.setReleaseTime(time);
        knowledgeMapper.insert(knowledge);
    }
}
